import KoaRouter from 'koa-router'
import {submitController} from '../controllers/submit'
import getAllOrdersController from '../controllers/getOrder'
import deleteOrderController from '../controllers/deleteOrder'
const submitRoute=new KoaRouter()

submitRoute.get('/getOrder',async(ctx)=>{
      const data=await new submitController().orders()
      ctx.body={
        data,
        message:'ok'
      }
})

submitRoute.post('/submitOrder',async(ctx)=>{
  console.log("submit路由接收到post请求");
  const payload=ctx.request.body
  console.log("接收到参数",payload);
  const res =await new submitController().createOrder(payload) 
  ctx.body={
    res,
    message:'ok'
  }
})

submitRoute.get('/getAllOrders',async(ctx)=>{
  console.log("ctx.request.query",ctx.request.query);
  const res=await new getAllOrdersController().getAllOrders(ctx.request.query)
  ctx.body=res
  console.log(res);
})

submitRoute.post('/deleteOrder',async(ctx)=>{
  const res=await new deleteOrderController().deleteOrder(ctx.request.body)
  console.log(res);
  ctx.body={
    message:'ok'
  }
})

export{
  submitRoute
} 
